package cn.wp.common.core.generate;

import cn.hutool.core.io.IoUtil;
import cn.wp.common.core.WpVar;
import cn.wp.common.core.generate.meta.Author;
import cn.wp.common.core.generate.meta.Table;
import cn.wp.common.core.generate.meta.TableColumn;
import org.thymeleaf.context.Context;

import java.io.InputStream;
import java.util.List;

/**
 * Dao生成类
 * Created by chenyb on 2019/10/22
 */
public class GenerateDaoTemplate extends GenerateCode {

    @Override
    public String tpl(){
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("templates/gen-code-tpl/Dao.tpl");
        String tpl = IoUtil.read(is, WpVar.ENCODE);
        IoUtil.close(is);
        return tpl;
    }

    @Override
    public String create(String tpl, Table table, Author author, List<TableColumn> tableColumnList) {
        Context ctx = new Context();
        ctx.setVariable("columnList",tableColumnList);
        ctx.setVariable("table",table);
        ctx.setVariable("author",author);
        return templateEngine.process(tpl,ctx);
    }

}
